home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / GAULEG.DEM < prev    next >
Text File  |  1991-04-29  |  906b  |  46 lines

  1. PROGRAM d4r8(input,output);
  2. (* driver for routine GAULEG *)
  3. CONST
  4.    npoint=10;
  5.    x1=0.0;
  6.    x2=1.0;
  7.    x3=10.0;
  8.    nval=10;
  9. TYPE
  10.    double = real;
  11.    darray=ARRAY [1..npoint] OF double;
  12. VAR
  13.    i,j : integer;
  14.    xx : real;
  15.    x,w : darray;
  16.  
  17. FUNCTION func(x: real): real;
  18. BEGIN
  19.    func := x*exp(-x)
  20. END;
  21.  
  22. FUNCTION sngl(x : real): real;
  23. BEGIN
  24.    sngl := x
  25. END;
  26.  
  27. (*$I GAULEG.PAS *)
  28.  
  29. BEGIN
  30.    gauleg(x1,x2,x,w,npoint);
  31.    writeln;
  32.    writeln('#':2,'x[i]':11,'w[i]':12);
  33.    FOR i := 1 to npoint DO BEGIN
  34.       writeln(i:2,x[i]:12:6,w[i]:12:6)
  35.    END;
  36. (* demonstrate the use of gauleg for an integral *)
  37.    gauleg(x1,x3,x,w,npoint);
  38.    xx := 0.0;
  39.    FOR i := 1 to npoint DO BEGIN
  40.       xx := xx+sngl(w[i])*func(sngl(x[i]))
  41.    END;
  42.    writeln;
  43.    writeln('Integral from GAULEG: ',xx:12:6);
  44.    writeln('Actual value: ',((1.0+x1)*exp(-x1)-(1.0+x3)*exp(-x3)):12:6)
  45. END.
  46.